package cn.hzking.gjmall.utils.helpers;

import android.support.annotation.ColorRes;
import android.support.v7.widget.RecyclerView;

import com.choices.divider.Divider;
import com.choices.divider.DividerItemDecoration;

/**
 * Created by Administrator on 2018/2/2.
 */

public final class GridDecorationHelper {
    private RecyclerView  recyclerView;
    private int mColor;
    private int mSize;

    public GridDecorationHelper(RecyclerView recyclerView, @ColorRes int colorId, int size) {
        this.recyclerView = recyclerView;
        this.mColor = colorId;
        this.mSize = size;
    }


    public RecyclerView addGridItemDecoration(){
        DividerItemDecoration itemDecoration = new DividerItemDecoration();
        itemDecoration.setDividerLookup(new AgileDividerLookup());
        recyclerView.addItemDecoration(itemDecoration);

        return  recyclerView;
    }

    class AgileDividerLookup extends DividerItemDecoration.SimpleDividerLookup {

        @Override
        public Divider getVerticalDivider(int position) {
            return new Divider.Builder()
                    .size(mSize)
                    .color(mColor)
                    .build();
        }

        @Override
        public Divider getHorizontalDivider(int position) {
            return new Divider.Builder()
                    .size(mSize)
                    .color(mColor)
                    .build();
        }
    }
}
